<template>
  <li>
    <label>
      <!-- v-model: 注意事项-->
      <input type="checkbox" :checked="todo.done"
        @change="handleCheck(todo.id)"/>
      <span>{{todo.content}}</span>
    </label>
    <button class="btn btn-danger"
        @click="handleDelete(todo.id, $event)">删除</button>
  </li>
</template>
<script>
export default {
  name: 'MyItem',
  props: {
    todo: {
      type: Object,
      required: true,
    },
    // checkTodo: {
    //   type: Function
    // },
    // deleteTodo: {
    //   type: Function
    // }
  },
  data() {
    return {}
  },
  methods: {
    handleCheck(id) {
      this.$emit('check-todo', id)
      // this.checkTodo(id)
    },
    handleDelete(id, event) {
      if(confirm(`删除 ${id} todo?`)) {
        // this.deleteTodo(id)
        this.$emit('delete-todo', id)
      }
    }
  }
}
</script>


<style scoped lang="css">
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li:hover {
  background-color: lightgrey;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:hover button {
  display: block;
  cursor: pointer;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

</style>